<?php


namespace App\Http\Controllers\api;


use App\Http\Controllers\Controller;
use App\Models\Article;
use App\Models\ArticleCode;
use App\Models\Miao;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;

class ProductController extends Controller
{

    /**
     * 产品详情查询
     * @param $id
     * @return array
     */
    public function show($id)
    {
        $data =  Article::where('id', $id)->first();
        if (!$data) {
            return $this->responseFailed('查询失败');
        }

        return $this->responseSuccess($data);
    }


    /**
     * 验证码验证
     * @param $id
     * @param $code
     * @return array
     */
    public function check($id, $code)
    {
        $data = ArticleCode::where(['article_id' => $id, 'code' => $code])->first();
        if (!$data) {
            return $this->responseFailed('验证失败');
        }

        return $this->responseSuccess($data);
    }


    /**
     * 撩小喵
     * @return array
     */
    public function miao(){
        $data = Miao::where('status',1)->first();
        if (!$data) {
            return $this->responseFailed('内容尚未编辑');
        }
        return $this->responseSuccess($data);
    }



    protected function responseSuccess($data)
    {
        return [
            'code' => 200,
            'msg' => 'ok',
            'data' => $data
        ];
    }


    protected function responseFailed($message)
    {
        return [
            'code' => 0,
            'msg' => $message,
            'data' => []
        ];
    }
}
